package dev.entao.travel

import dev.entao.core.HttpService
import dev.entao.core.SweetApp
import dev.entao.core.controllers.KeyLabelController
import dev.entao.core.controllers.UploadController
import dev.entao.core.slices.*
import dev.entao.sql.ConnLook
import dev.entao.sql.WebContextConnMaker
import dev.entao.sql.tableMigrate
import dev.entao.travel.admin.AccountPages
import dev.entao.travel.admin.MallPages
import dev.entao.travel.admin.MerchantPages
import dev.entao.travel.admin.UserPages
import dev.entao.travel.model.Account
import dev.entao.travel.model.User

class App(httpService: HttpService) : SweetApp(httpService), HttpTimer {

    override val appName: String = "管理后台"

    override fun onConfig() {
        ConnLook.maker = WebContextConnMaker()
    }

    override fun onCreate() {
        AreaStorage.load(httpService)

        httpService.apply {
            addController(UploadController::class)
            addController(KeyLabelController::class)

            addController(IndexPage::class)
            addController(AccountPages::class, MallPages::class, MerchantPages::class, UserPages::class)


            addSlice(TimerSlice(this@App))
            addSlice(TokenSlice)
            addSlice(SessionSlice)
            addSlice(TickSlice)
        }
        tableMigrate(
            Account::class,
            User::class,
        )

    }

    override fun onHttpTimer(dayOfMonth: Int, hour: Int, minute: Int) {

    }

    override fun onHour(h: Int) {

    }

    override fun onMinute(m: Int) {
    }

}